package test;

import java.rmi.RemoteException;

import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;

import com.michelin.crm.mars.WS_ImportUserInfoStub;
import com.thoughtworks.xstream.core.util.Base64Encoder;

public class CallMarsWebServicePOC {

    /**
     * @param args
     * @throws RemoteException 
     */
    public static void main(String[] args) throws RemoteException {
        String url = "http://marsns.chinacloudapp.cn:9022/MARSR5/WS/MARS%20W1%20ERM%20Dealer%201/Codeunit/WS_ImportUserInfo?tenant=r5dealer1";
        //url = EnDecoderUtils.encode(url);
        WS_ImportUserInfoStub stub = new WS_ImportUserInfoStub(url);
        Options options = stub._getServiceClient().getOptions();
        HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
        auth.setPreemptiveAuthentication(true);
        auth.setUsername("r5dealer1\\alan");
        auth.setPassword("Michelin01");
        //auth.setPassword("6g4wJWw+8wbDzb2cgPOPhocapB3mzY4TgCR7W8Qj7bo=");
        options.setProperty(HTTPConstants.AUTHENTICATE,auth);
        
        WS_ImportUserInfoStub.UserSetup[] userSetupArray = new WS_ImportUserInfoStub.UserSetup[1];
        WS_ImportUserInfoStub.UserSetup userSetup = new WS_ImportUserInfoStub.UserSetup();
        userSetup.setUserID("Test100");
        userSetup.setSalespersonCode("Test100");
        userSetup.setCashRegServiceCenter("001-01");
        userSetup.setAuthorizationLevel("SUPER");
        userSetup.setModifyRole("EM_SUPER");
        userSetup.setLoginServCenter("001-01");
        userSetupArray[0] = userSetup;
        
        WS_ImportUserInfoStub.Salesperson[] salespersonArray = new WS_ImportUserInfoStub.Salesperson[1];
        WS_ImportUserInfoStub.Salesperson salesperson = new WS_ImportUserInfoStub.Salesperson();
        salesperson.setName("Test100 Tester");
        salesperson.setSalespersonCode("Test100");
        salespersonArray[0] = salesperson;
        
        WS_ImportUserInfoStub.TireSetupUser[] tireSetupUserArray = new WS_ImportUserInfoStub.TireSetupUser[1];
        WS_ImportUserInfoStub.TireSetupUser tireSetupUser = new WS_ImportUserInfoStub.TireSetupUser();
        tireSetupUser.setUserID("Test100");
        tireSetupUserArray[0] = tireSetupUser;
        
        WS_ImportUserInfoStub.UserServCenter[] userServCenterArray = new WS_ImportUserInfoStub.UserServCenter[1];
        WS_ImportUserInfoStub.UserServCenter userServCenter = new WS_ImportUserInfoStub.UserServCenter();
        userServCenter.setServiceCenter("001-01");
        userServCenter.setUserID("Test100");
        userServCenterArray[0]=userServCenter;
        
        WS_ImportUserInfoStub.CashRegUser[] cashRegUserArray = new WS_ImportUserInfoStub.CashRegUser[1];
        WS_ImportUserInfoStub.CashRegUser cashRegUser = new WS_ImportUserInfoStub.CashRegUser();
        cashRegUser.setName("Test100");
        cashRegUser.setSalespersonCode("Test100");
        cashRegUserArray[0]= cashRegUser;
        
        WS_ImportUserInfoStub.EasyRollOutLogUser[] easyRollOutLogUserArray = new WS_ImportUserInfoStub.EasyRollOutLogUser[1];
        WS_ImportUserInfoStub.EasyRollOutLogUser easyRollOutLogUser = new WS_ImportUserInfoStub.EasyRollOutLogUser();
        easyRollOutLogUserArray[0] = easyRollOutLogUser;
        
        WS_ImportUserInfoStub.ProcessUserRollOut processUserRollout = new WS_ImportUserInfoStub.ProcessUserRollOut();
        WS_ImportUserInfoStub.Root root = new WS_ImportUserInfoStub.Root();
        root.setUserSetup(userSetupArray);
        root.setSalesperson(salespersonArray);
        root.setTireSetupUser(tireSetupUserArray);
        root.setUserServCenter(userServCenterArray);
        root.setCashRegUser(cashRegUserArray);
        processUserRollout.setEasyRollOutUserImport(root);
        
        WS_ImportUserInfoStub.Root0 root0 = new WS_ImportUserInfoStub.Root0();
        root0.setEasyRollOutLogUser(easyRollOutLogUserArray);
        processUserRollout.setEasyRollOutUserExport(root0);
        WS_ImportUserInfoStub.ProcessUserRollOut_Result response = stub.processUserRollOut(processUserRollout);
        WS_ImportUserInfoStub.Root0 result = response.getEasyRollOutUserExport();
        WS_ImportUserInfoStub.EasyRollOutLogUser[] returnArray = result.getEasyRollOutLogUser();
        for(int index = 0;index < returnArray.length; index++){
            WS_ImportUserInfoStub.EasyRollOutLogUser currentEasyRollOutLogUser = returnArray[index];
            System.out.println("EntryNo:" + currentEasyRollOutLogUser.getEntryNo());
            System.out.println("UserId:" + currentEasyRollOutLogUser.getUserID());
            System.out.println("EntryType:" + currentEasyRollOutLogUser.getEntryType());
            System.out.println("CreateDate:" + currentEasyRollOutLogUser.getCreationDate());
            System.out.println("RawDataCode:" + currentEasyRollOutLogUser.getRawDataCode());
            System.out.println("ErrorInfoText:" + currentEasyRollOutLogUser.getErrorInfoText());
        }
        
        
    
    }

}
